// index.js
var util = require('../../utils/util.js')
const app = getApp()
let that
let userInfo
Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    hasAdmin: false
  },

  onLoad: function () {
    that = this
    userInfo = wx.getStorageSync('userInfo') || false
    if (userInfo) {
      app.reg(userInfo)
      that.setData({
        userInfo: userInfo,
        hasUserInfo: true
      })
      if (userInfo.openId === "oVxJd5bVXUqbP6gc0qVUQr2T_Vlk") {
        that.setData({
          hasAdmin: true
        })
      }
    } else if (!that.data.hasUserInfo) {
      app.userInfoReadyCallback = res => {
        that.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
        userInfo = res.userInfo
        util.addLogs("准备注册")
        app.reg(userInfo)
        if (userInfo.openId === "oVxJd5bVXUqbP6gc0qVUQr2T_Vlk") {
          that.setData({
            hasAdmin: true
          })
        }
      }
    }
  },

  onShareAppMessage: function () {

  },

  getUserInfo: function () {
    app.getUserInfo()
  },

  seeLogs: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  }
})